

import time
import pandas as pd
from cls.orm.main import PG
from cls.finance.datas.tudata import TradeDatas
from cls.finance.datas.top.topchg import TopChange
from cls.finance.stock import ShareItem

#  用到订阅者模式，使用设计模式，用到行情类，下订单类，行情类
#  如果经常涨停，则在下午也没关系，如果是很少涨停，而又是在下午则不考虑，大盘子的不考虑，即便考虑了，也要马上出来
class RiseLimit():

    def __init__(self):
        self.data = TradeDatas()
        self.realtime = TopChange()
        self.stock = None
        pass

    #  有涨停潜力的个股，最迟一分钟获取一次行情
    def getWillRise(self):
        df = self.realtime.getTopRise()
        df = df[df["ts_code"] != '603217']
        for index, row in df.iterrows():
            stock = self.getShareItem(row['ts_code'])
            stock.statZT()
            # print(row['ts_code'])

        # print(df.columns)
        # print(df['pct_chg'])


    def getShareItem(self, code):
        if self.stock is None:
            self.stock = ShareItem(code)
        else:
            self.stock.setCode(code)
        return self.stock

    def testSystem(self):
        buy = False
        sell = True
        st = self.getShareItem()
        codes = st.getAllStockCodes()
        tradeInfo = []
        for index, row in codes.iterrows():  # 遍历所有股票
            st.setCode(row['ts_code'])
            datas = st.getNumDatas('20190620', 120)
            for id, rowd in datas.iterrows():  # 测算所有
                if(rowd['close'] == rowd['high']) & (rowd['pct_chg'] > 9.8) and sell:
                    buy = True;
                    buyInfo = []
                if (rowd['close'] != rowd['high']) & ((rowd['high'] - rowd['pre_close']) / rowd['pre_close'] * 100 > 9.2) and buy:
                    sell = True
                    buy = False
                    calProfit = 1000
                    sellInfo = []
                    tradeInfo.append(buyInfo,sellInfo)
            tradeInfo.append(tradeInfo)





o = RiseLimit()
o.getWillRise()


